package cn.xiaou.view;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import cn.xiaou.domain.User;
import cn.xiaou.draw.MyJButtom;
import cn.xiaou.utils.ImageManagerUtils;




public class MainFrame extends JFrame implements ActionListener {
	
	private static final long serialVersionUID = 1L;
	private User user = null;
//	private JMenuBar MBar;//菜单条
//	private JMenu User,ExchangeHall,About;//菜单项目-用户，交易大厅，关于
//	private JMenuItem UserInfo,PersonalHoldings,logout,StockInfo,Help,AboutUs,RealName,Replenish;
	private ImageIcon  MainFrameBg;
	//一级菜单内容-用户信息-个人所持股-注销-股票资料-卖出-帮助-关于我们
	private JButton userInfoButton;
	private JButton realNameButton;
	private JButton replenishButton;
	private JButton personalHoldingsButton;
	private JButton stockInfoButton;
	private JButton aboutUsBtton;
	private JButton logoutButton;
	private JButton close;
	public MainFrame(User user) {
		this.user = user;
		if(this.user == null) {
			Object[] options = { "确定"}; 
			JOptionPane.showOptionDialog(null, "数据发生严重丢失", "警告", 
					JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, 
					null, options,options[0]); 
		}
		setIconImage(getToolkit().getImage(ImageManagerUtils.icoUrl));//设置图标
		setSize(1000,800);//设置窗体大小
		setTitle("股票交易系统");//设置窗体标题
		//显示窗体
		setLocationRelativeTo(null);//窗体居中
		setResizable(false);//窗体大小不可以调
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(null);
		
		setUndecorated(true);
	    setBackground(new Color(0,0,0,0));
		
		
		
//		Font Fontstyle =new Font("华文彩云", Font.PLAIN, 20);
//		
//		MBar=new JMenuBar();
//		User=new JMenu("用户");
//		User.setFont(Fontstyle);
//		ExchangeHall=new  JMenu("交易大厅");
//		ExchangeHall.setFont(Fontstyle);
//		About=new JMenu("关于");
//		About.setFont(Fontstyle);
//		
//
//		
//		
//		UserInfo=new JMenuItem("用户信息");
//		UserInfo.setFont(Fontstyle);
//		UserInfo.addActionListener(this);
//		PersonalHoldings=new JMenuItem("个人所持股");
//		PersonalHoldings.setFont(Fontstyle);
//		logout=new JMenuItem("注销");
//		logout.setFont(Fontstyle);
//		logout.addActionListener(this);
//		StockInfo=new JMenuItem("股票资料");
//		StockInfo.setFont(Fontstyle);
//		StockInfo.addActionListener(this);
//		Help=new JMenuItem("帮助");
//		Help.setFont(Fontstyle);
//		AboutUs=new JMenuItem("关于我们");
//		AboutUs.setFont(Fontstyle);
//		AboutUs.addActionListener(this);
//		RealName=new JMenuItem("实名认证");
//		RealName.setFont(Fontstyle);
//		RealName.addActionListener(this);
//		Replenish=new JMenuItem("充值");
//		Replenish.setFont(Fontstyle);
//		
//		MBar.add(User);
//		User.add(UserInfo);
//		User.add(Replenish);
//		User.add(RealName);
//		User.add(PersonalHoldings);
//		User.add(logout);
//		
//		
//		
//		MBar.add(ExchangeHall);
//		ExchangeHall.add(StockInfo);
//		
//		MBar.add(About);
//		About.add(Help);
//		About.add(AboutUs);
//		add(MBar,BorderLayout.NORTH);
		
//		bg=new ImageIcon(ImageManagerUtils.MainFrameBg);
//		JLabel b=new JLabel(bg);
//		add(b, BorderLayout.CENTER);
		
	    
	    MainFrameBg=new ImageIcon(ImageManagerUtils.MainFrameBg);
	    JLabel mfbg=new JLabel(MainFrameBg);
	    mfbg.setBounds(0, 0, 1000, 800);
	    add(mfbg);
	    
	    

		//用户
		userInfoButton=new MyJButtom(ImageManagerUtils.userInfoBg);
		userInfoButton.setBounds(50, 50, 60, 60);
		userInfoButton.addActionListener(this);
		add(userInfoButton,0);
		//实名认证
		realNameButton=new MyJButtom(ImageManagerUtils.realNameICO); 
		realNameButton.setBounds(50, 150, 60, 60);
		realNameButton.addActionListener(this);
		add(realNameButton,0);
		//充值
		replenishButton=new MyJButtom(ImageManagerUtils.replenishBg);
		replenishButton.setBounds(150, 50, 60, 60);
		replenishButton.addActionListener(this);
		add(replenishButton,0);
		//个人股票
		personalHoldingsButton=new MyJButtom(ImageManagerUtils.personalHoldingsBg);
		personalHoldingsButton.setBounds(50, 250, 60, 60);
		personalHoldingsButton.addActionListener(this);
		add(personalHoldingsButton,0);
		//股票交易
		stockInfoButton=new MyJButtom(ImageManagerUtils.stockInfoBg);
		stockInfoButton.setBounds(250, 50, 60, 60);
		stockInfoButton.addActionListener(this);
		add(stockInfoButton,0);
		//关于我们
		 aboutUsBtton=new MyJButtom(ImageManagerUtils.aboutUsBg);
		aboutUsBtton.setBounds(900, 50, 60, 60);
		aboutUsBtton.addActionListener(this);
		add(aboutUsBtton,0);
		//注销
		 logoutButton=new MyJButtom(ImageManagerUtils.logoutBg);
		logoutButton.setBounds(900, 150, 60, 60);
		logoutButton.addActionListener(this);
		add(logoutButton,0);
		//关闭
		 close=new MyJButtom(ImageManagerUtils.b5);
		close.setBounds(925, 725, 60, 60);
		close.addActionListener(this);
		add(close,0);
		
		
		setVisible(true);
	}
	
	
//	 public static void main(String[] args) {  
//	  new MainFrame(null);  
//	}


	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == userInfoButton) {
			this.setEnabled(false);
			new Information(user, this);
		}else if(e.getSource() == realNameButton ) {
			this.setEnabled(false);
			new RealnNameFrame(user, this);
		}else if(e.getSource() == replenishButton) {
			this.setEnabled(false);
			new RechargeView(user,this);
		}else if(e.getSource() == personalHoldingsButton) {
			//个人股票
			new PsersonStock(user, this);
			this.setVisible(false);
		}else if(e.getSource() == stockInfoButton) {
			new StockView(user,this);
			this.setVisible(false);
		}else if(e.getSource() == aboutUsBtton) {
			new AboutView(this);
		}else if(e.getSource() == logoutButton) {
			user=null;
			new LoginView();
			dispose();
			
		}else if(e.getSource() == close) {
			System.exit(0);
		}
	}  

	 
	 
	 
	 
//	@Override
//	public void actionPerformed(ActionEvent e) {
//		if(e.getSource()==AboutUs) {
//			new AboutView(this);
//			this.setEnabled(false);
//		}else if(e.getSource()==logout) {
//			System.out.println("123");
//			new LoginView();
//			this.setVisible(false);
//		}else if(e.getSource() == RealName) {
//			new RealnNameFrame(user,this);
//			this.setEnabled(false);
//		}else if(e.getSource() == UserInfo) {
//			new Information(user,this);
//			this.setEnabled(false);
//		}else if(e.getSource() == StockInfo) {
//			new StockView(user);
//		}
//		
//	}	
	
}